import dynamic from 'dva/dynamic';

// wrapper of dynamic
const dynamicWrapper = (app, models, component) => dynamic({
  app,
  models: () => models.map(m => import(`../models/${m}.js`)),
  component,
});

// nav data
export const getNavData = app => [
  {
    component: dynamicWrapper(app, ['user', 'login'], () => import('../layouts/BasicLayout')),
    layout: 'BasicLayout',
    name: '首页', // for breadcrumb
    path: '/',
    children: [
      {
        name: '考试安排',
        path: 'exam',
        icon: 'calendar',
        children: [
          {
            name: '考试列表',
            path: 'list',
            component: dynamicWrapper(app, ['exam'], () => import('../routes/Exam/ExamList')),
          },
          {
            name: '新增考试',
            path: 'add',
            component: dynamicWrapper(app, ['exam', 'paper'], () => import('../routes/Exam/StepForm')),
            children: [
              {
                path: 'confirm',
                component: dynamicWrapper(app, ['exam'], () => import('../routes/Exam/StepForm/Step2')),
              },
              {
                path: 'result',
                component: dynamicWrapper(app, ['exam'], () => import('../routes/Exam/StepForm/Step3')),
              },
            ],
          },
        ],
      },
      {
        name: '试卷管理',
        path: 'paper',
        icon: 'file-text',
        children: [
          {
            name: '试卷列表',
            path: 'list',
            component: dynamicWrapper(app, ['paper'], () => import('../routes/Paper/PaperList')),
          },
          {
            name: '新增试卷',
            path: 'add',
            component: dynamicWrapper(app, ['paper', 'course'], () => import('../routes/Paper/PaperForm')),
          },
        ],
      },
      {
        name: '科目管理',
        path: 'course',
        icon: 'folder-open',
        component: dynamicWrapper(app, ['course'], () => import('../routes/Course/CourseList')),
      },
      {
        name: '学员管理',
        path: 'student',
        icon: 'user',
        component: dynamicWrapper(app, ['student'], () => import('../routes/Student/StudentList')),
      },
      {
        name: '成绩查询',
        path: 'score',
        icon: 'solution',
        component: dynamicWrapper(app, ['score'], () => import('../routes/Score/ScoreList')),
      },
    ],
  },
  {
    component: dynamicWrapper(app, [], () => import('../layouts/UserLayout')),
    path: '/user',
    layout: 'UserLayout',
    children: [
      // {
      //   name: '帐户',
      //   icon: 'user',
      //   path: 'user',
      //   children: [
      //     {
      //       name: '登录',
      //       path: 'login',
      //       component: dynamicWrapper(app, ['login'], () => import('../routes/User/Login')),
      //     },
      //     {
      //       name: '注册',
      //       path: 'register',
      //       component: dynamicWrapper(app, ['register'], () => import('../routes/User/Register')),
      //     },
      //     {
      //       name: '注册结果',
      //       path: 'register-result',
      //       component: dynamicWrapper(app, [], () => import('../routes/User/RegisterResult')),
      //     },
      //   ],
      // },
    ],
  }
];
